package com.qingxin.sys.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

public class HttpParams {
	
	public static class Param{
		private String name;
		private String value;
		protected Param(String name, String value) {
			this.name = name;
			this.value = value;
		}
		protected String getName() {
			return name;
		}
		protected String getValue() {
			return value;
		}
	}
	
	public HttpParams() {
	}
	

	public HttpParams(boolean post, String charset) {
		this.post = post;
		this.charset = charset;
	}

	
	private boolean post;
	private String charset;
	private List<Param> headers;
	private List<Param> params;
	
	private String data;
	
	public boolean isPost() {
		return post;
	}
	public void setPost(boolean post) {
		this.post = post;
	}
	
	public String getCharset() {
		return charset;
	}
	public void setCharset(String charset) {
		this.charset = charset;
	}
	
	protected List<Param> getHeaders() {
		return headers;
	}
	public void addHeader(String name, String value){
		if(headers == null){
			headers = new ArrayList<>();
		}
		headers.add(new Param(name, value));
	}
	public void addHeaders(Map<String, String> headerMap){
		if(headers == null){
			headers = new ArrayList<>();
		}
		Set<SortedMap.Entry<String, String>> entrySet = headerMap.entrySet();
		for(SortedMap.Entry<String, String> entry : entrySet){
			String key = entry.getKey();
			String value = (String) entry.getValue();
			headers.add(new Param(key, value));
		}
	}
	
	protected List<Param> getParams() {
		return params;
	}
	public void setParams(List<Param> params) {
		this.params = params;
	}
	public void addParam(String name, String value){
		if(params == null){
			params = new ArrayList<>();
		}
		params.add(new Param(name, value));
	}
	public void addParams(Map<String, String> paramMap){
		if(params == null){
			params = new ArrayList<>();
		}
		Set<SortedMap.Entry<String, String>> entrySet = paramMap.entrySet();
		for(SortedMap.Entry<String, String> entry : entrySet){
			String key = entry.getKey();
			String value = (String) entry.getValue();
			params.add(new Param(key, value));
		}
	}


	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}
	
	
	
}
